var Filter = function () {
    function not(filter) {
        return function (value) {
            return !Filter.parse(filter)(value);
        };
    }

    function or(/* arguments */) {
        var args = arguments;
        var length = args.length;
        return function (value) {
            for (var i = 0; i < length; i++) {
                if (Filter.parse(args[i])(value)) {
                    return true;
                }
            }
            return false;
        };
    }

    function and(/* arguments */) {
        var args = arguments;
        var length = args.length;
        return function (value) {
            for (var i = 0; i < length; i++) {
                if (!Filter.parse(args[i])(value)) {
                    return false;
                }
            }
            return true;
        };
    }

    function endsWith(/* arguments */) {
        var suffix = arguments;
        var length = suffix.length;
        return function (value) {
            var valueLength = value.length;
            for (var i = 0; i < length; i++) {
                if (value.indexOf(suffix[i], valueLength - suffix[i].length) !== -1) {
                    return true;
                }
            }
            return false;
        };
    }

    function startsWith(/* arguments */) {
        var prefix = arguments;
        var length = prefix.length;
        return function (value) {
            for (var i = 0; i < length; i++) {
                if (value.indexOf(prefix[i]) == 0) {
                    return true;
                }
            }
            return false;
        };
    }

    function contains(/* arguments */) {
        var args = arguments;
        var length = args.length;
        return function (value) {
            for (var i = 0; i < length; i++) {
                if (value.indexOf(args[i])) {
                    return true;
                }
            }
            return false;
        };
    }

    function parse(arg) {
        if (typeof(arg) == "string") {
            /*			var ptrn = Filter_compile(arg);
             return function(value) {
             return Filter_test(ptrn, value);
             }; */
            // TODO: Tie together with java File thing
        } else if (typeof(arg) == "function") {
            return arg;
        } else if (arg instanceof RegExp) {
            return function (value) {
                return arg.test(value);
            };
        }

        throw "Invalid Filter type: " + arg;
    }

    return {
        not: not,
        and: and,
        or: or,
        endsWith: endsWith,
        startsWith: startsWith,
        contains: contains,
        parse: parse
    };
}();